/**
 * Mobile detection and responsive utilities
 */

/**
 * Check if the current device is a mobile device
 * Uses both user agent detection and screen size
 * @returns {boolean} True if the device is mobile
 */
export function isMobileDevice () {
    const userAgent = navigator.userAgent.toLowerCase();
    return /iphone|ipad|ipod|android|blackberry|windows phone|opera mini|silk|/i.test(userAgent) || window.innerWidth < 768;
}

/**
 * Check if the current device is a tablet
 * @returns {boolean} True if the device is a tablet
 */
export function isTabletDevice () {
    const userAgent = navigator.userAgent.toLowerCase();
    const isTabletUserAgent = /ipad|android(?!.*mobile)/i.test(userAgent);
    const isMediumScreen = window.innerWidth >= 768 && window.innerWidth <= 1024;

    return isTabletUserAgent || isMediumScreen;
}

/**
 * Apply mobile-specific styles to a component
 * @param {Object} component - Vue component
 */
export function applyMobileStyles (component) {
    if (localStorage.getItem('isMobile') === 'true') {
        // Apply mobile-specific styles or configurations
        return {
            ...component,
            props: {
                ...component.props,
                size: {
                    type: String,
                    default: 'small'
                },
                labelPosition: {
                    type: String,
                    default: 'top'
                }
            }
        };
    }

    return component;
}

/**
 * Get responsive column span based on device type
 * @returns {Object} Column spans for different device types
 */
export function getResponsiveColumnSpan () {
    if (localStorage.getItem('isMobile') === 'true') {
        return {
            xs: 24,
            sm: 24,
            md: 24,
            lg: 24,
            xl: 24
        };
    }

    if (isTabletDevice()) {
        return {
            xs: 24,
            sm: 12,
            md: 12,
            lg: 8,
            xl: 6
        };
    }

    return {
        xs: 24,
        sm: 12,
        md: 8,
        lg: 6,
        xl: 4
    };
}

/**
 * Add mobile detection to Vue instance
 * @param {Object} Vue - Vue instance
 */
export function installMobileDetection (Vue) {
    console.warn('installMobileDetection 方法已废弃，请使用 Vuex store 来管理移动设备状态');
}
